package com.imxinxin.common.tools.http;

import com.imxinxin.common.model.KVEntry;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class HttpConfig {

    public static final String GBK = "GBK";
    public static final String UTF_8 = "UTF-8";

    public static final String FORM_URLENCODED = "application/x-www-form-urlencoded;charset=UTF-8";
    public static final String JSON = "application/json;charset=UTF-8";

    public static final String POST = "POST";
    public static final String GET = "GET";


    private String urlPath;
    @Builder.Default
    private String readCharset = UTF_8;
    @Builder.Default
    private String sendCharset = UTF_8;
    @Builder.Default
    private String requestMethod = GET;
    private List<KVEntry<String, String>> headers;
    private byte[] sendBytes;
    @Builder.Default
    private int connectTimeout = 2000;
    @Builder.Default
    private int readTimeout = 10000;
    @Builder.Default
    private boolean useCaches = false;
    @Builder.Default
    private ResultTypeEnum resultType = ResultTypeEnum.STRING;
    private String filePath;//如: /abc/ddd
    private String fileName;//如: a.txt
    private Proxy proxy;

    public void addHeader(String key, String value) {
        if (headers == null) {
            headers = new ArrayList<>();
        }
        headers.add(new KVEntry<>(key, value));
    }


}
